package com.inspinia.upms.common.model.org;


import com.fasterxml.jackson.annotation.JsonFormat;
import com.inspinia.base.pagination.PageQueryVo;
import com.inspinia.upms.common.model.user.UpmsUserStatus;

import java.util.Date;


/**
 * 组织机构和部门的vo
 * Created by veblen on 16/9/7.
 */
public class UpmsOrgDeptVo extends PageQueryVo {

    /**
     * id字段中type和id的分隔符
     */
    public static final String ID_SPLIT = "-";

    /**
     * 部门的icon
     */
    public static final String DEPT_ICON = "icon-standard-door";

    /**
     * 岗位的icon
     */
    public static final String POST_ICON = "icon-standard-monitor";

    /**
     * id,由type加"-"加自身id组成,比如"1-2,2-1";
     */
    private String id;
    /**
     * 名称
     */
    private String name;

    /**
     * 类型:1-组织,2-部门
     */
    private UpmsOrgDeptVoType type;

    /**
     * 父节点id
     */
    private String pid;

    /**
     * 原始id
     */
    private Long originId;

    /**
     * icon图标
     */
    private String icon;

    /** 排序 */
    private Integer seq;
    /** 描述*/
    private String remark;
    /** 省id*/
    private Long provinceId;
    /** 市id*/
    private Long cityId;
    /** 县id*/
    private Long countyId;
    /** 状态*/
    private UpmsUserStatus status;
    /** 创建者*/
    private String createBy;
    /** 修改者*/
    private String updateBy;
    /** 创建时间*/
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;
    /** 修改时间*/
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date updateTime;


    public UpmsOrgDeptVo(){

    }
    /**
     * 构造器,方便构造以id和type组合的id
     *
     * @param id
     * @param name
     * @param type
     * @param pid
     */
    public UpmsOrgDeptVo(Long id, String name, UpmsOrgDeptVoType type, Long pid) {
        this.originId = id;
        setId(id, type);
        this.name = name;
        this.type = type;
        setPid(pid, type);
//        setIcon(type);
    }

    /**
     * 根据类型设置icon
     *
     * @param type
     */
    private void setIcon(UpmsOrgDeptVoType type) {

        if (type == UpmsOrgDeptVoType.dept) {
            //部门的父节点的类型应该是组织。
            setIcon(DEPT_ICON);
        } else if (type == UpmsOrgDeptVoType.post) {
            setIcon(POST_ICON);
        } else {
            //如果是组织的话,需要分根节点和子节点来设置不同的icon。
            if (pid.equals(UpmsOrgDeptVoType.org.getCode() + ID_SPLIT + "0") || pid.equals(UpmsOrgDeptVoType.org.getCode() + ID_SPLIT + "null")) {
                setIcon(UpmsOrganizationVo.ROOT_ICON);
            } else {
                setIcon(UpmsOrganizationVo.DEFAULT_ICON);
            }
        }
    }

    public Long getOriginId() {
        return originId;
    }

    public void setOriginId(Long originId) {
        this.originId = originId;
    }

    public String getIcon() {
        return icon;
    }

    public void setIcon(String icon) {
        this.icon = icon;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public void setId(Long id, UpmsOrgDeptVoType type) {
        this.id = type.getCode() + ID_SPLIT + id;
    }

    public void setPid(Long pid, UpmsOrgDeptVoType type) {
        if (type == UpmsOrgDeptVoType.dept) {
            //部门的父节点的类型应该是组织。
            this.pid = UpmsOrgDeptVoType.org.getCode() + ID_SPLIT + pid;
        } else if (type == UpmsOrgDeptVoType.post) {
            this.pid = UpmsOrgDeptVoType.dept.getCode() + ID_SPLIT + pid;
        } else {
            this.pid = type.getCode() + ID_SPLIT + pid;
        }
    }


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public UpmsOrgDeptVoType getType() {
        return type;
    }

    public void setType(UpmsOrgDeptVoType type) {
        this.type = type;
    }

    public String getPid() {
        return pid;
    }

    public void setPid(String pid) {
        this.pid = pid;
    }

    public Integer getSeq() {
        return seq;
    }

    public void setSeq(Integer seq) {
        this.seq = seq;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public Long getProvinceId() {
        return provinceId;
    }

    public void setProvinceId(Long provinceId) {
        this.provinceId = provinceId;
    }

    public Long getCityId() {
        return cityId;
    }

    public void setCityId(Long cityId) {
        this.cityId = cityId;
    }

    public Long getCountyId() {
        return countyId;
    }

    public void setCountyId(Long countyId) {
        this.countyId = countyId;
    }

    public UpmsUserStatus getStatus() {
        return status;
    }

    public void setStatus(UpmsUserStatus status) {
        this.status = status;
    }

    public String getCreateBy() {
        return createBy;
    }

    public void setCreateBy(String createBy) {
        this.createBy = createBy;
    }

    public String getUpdateBy() {
        return updateBy;
    }

    public void setUpdateBy(String updateBy) {
        this.updateBy = updateBy;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }
}
